package com.yc.game.cms.controller;

import com.yc.game.cms.common.ServerResponse;
import com.yc.game.cms.pojo.Doubt;
import com.yc.game.cms.service.DoubtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DoubtController {
    @Autowired
    private DoubtService doubtService;
    /**
     * 获取所有的问题
     */
    @RequestMapping("page/doubt")
    public String doubtPage(ModelMap modelMap) {
        List<Doubt> doubtList = doubtService.getAll();
        modelMap.addAttribute("doubtList", doubtList);
        return "doubt";
    }

    /**
     * 修改问题
     */
    @RequestMapping("doubt/editDoubt")
    @ResponseBody
    public ServerResponse editDoubt(Doubt doubt) {
        int result = doubtService.updateDoubt(doubt);
        if (result > 0) {
            return ServerResponse.createBySuccessMessage("更新成功");
        }
        return  ServerResponse.createByErrorMessage("更新失败");
    }
    /**
     * 删除问题
     */
    @RequestMapping("doubt/deleteById")
    @ResponseBody
    public ServerResponse deleteById(@RequestParam("doubtId") Integer doubtId) {
        int result  = doubtService.deleteById(doubtId);
        if (result > 0) {
            return ServerResponse.createBySuccessMessage("删除成功");
        }
        return  ServerResponse.createByErrorMessage("删除 失败");
    }
}
